"use strict";
cc._RF.push(module, '458130T0AxA6I/r0SY2/GFE', 'LevelMeun');
// scripts/Game/Page/LevelMeun.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __generator = (this && this.__generator) || function (thisArg, body) {
    var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
    return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
    function verb(n) { return function (v) { return step([n, v]); }; }
    function step(op) {
        if (f) throw new TypeError("Generator is already executing.");
        while (_) try {
            if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
            if (y = 0, t) op = [op[0] & 2, t.value];
            switch (op[0]) {
                case 0: case 1: t = op; break;
                case 4: _.label++; return { value: op[1], done: false };
                case 5: _.label++; y = op[1]; op = [0]; continue;
                case 7: op = _.ops.pop(); _.trys.pop(); continue;
                default:
                    if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
                    if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
                    if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
                    if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
                    if (t[2]) _.ops.pop();
                    _.trys.pop(); continue;
            }
            op = body.call(thisArg, _);
        } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var data_control_1 = require("../../engines/libs/data_control");
var gameMode_json_1 = require("../../engines/managers/gameContent/gameMode_json");
var PageBase_1 = require("../Base/PageBase");
var Enum_1 = require("../Enum");
var MainRoot_1 = require("../MainRoot");
var LevelBtn_1 = require("../Obj/LevelBtn");
//电子邮件puhalskijsemen@gmail.com
//源码网站 开vpn全局模式打开 http://web3incubators.com/
//电报https://t.me/gamecode999
//网页客服 http://web3incubators.com/kefu.html
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property, menu = _a.menu, disallowMultiple = _a.disallowMultiple;
var LevelMeun = /** @class */ (function (_super) {
    __extends(LevelMeun, _super);
    function LevelMeun() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.pagePrefab = null;
        _this.btnPrefab = null;
        _this.pageNode = null;
        _this.pageTagNode = null;
        _this.lbMode = null;
        _this.lbAddition = null;
        _this.lbHpAddition = null;
        _this.atkAdditionNode = null;
        _this.btn_unlockAll = null;
        _this.gouZiNode = null;
        _this.lb_GouZi = null;
        /** 神奇汉字--模式 */
        _this.ShenQiHanZi = null;
        _this.level_Save_Content = "level_Save_Content"; // 所有模式的关卡信息存储键值
        _this.pages = [];
        _this.curPageIndex = 0;
        _this.pageAddNum = 0;
        return _this;
    }
    LevelMeun.prototype.OnPageOpen = function (prams) {
        return __awaiter(this, void 0, void 0, function () {
            var object, keyLength, objectNum, key, needPageNum, i, page, farLevel, allContent, object_1, curPageIndex;
            return __generator(this, function (_a) {
                switch (_a.label) {
                    case 0:
                        _super.prototype.OnPageOpen.call(this, prams);
                        object = MainRoot_1.default.LevelSystem.GetModeLevelInfo(this.m_mode);
                        keyLength = Object.keys(object).length;
                        if (this.m_mode == gameMode_json_1.GAME_MODE.NORMAL) {
                            object[keyLength + 1] = {
                                mode: 0,
                                subPower: 2,
                                //@ts-ignore
                                levelImg: "jjj_xuanguan_5",
                                bundleName: "normalMode",
                                name: "level_abb_00002",
                                level: 5,
                                levelType: 1,
                                gameAloneBundle: "level_abb_00002",
                                tips: "下",
                                title: "无尽模式",
                                winText: "救命，AI绘画把我画成狗了！",
                                loseText: "救命，AI绘画把我画成狗了！",
                                levelTitle: "无尽模式",
                                infinityFlag: true,
                                levelNum: keyLength + 1,
                            };
                        }
                        objectNum = 0;
                        for (key in object) {
                            // console.log(object[key]["hot"] == "hot");
                            objectNum += 1;
                        }
                        needPageNum = Math.ceil(objectNum / 6);
                        for (i = 0; i < needPageNum; i++) {
                            page = cc.instantiate(this.pagePrefab);
                            this.pageNode.getComponent(cc.PageView).addPage(page);
                            this.pages.push(page);
                        }
                        this.lbMode.string = gameMode_json_1.default()[this.m_mode].explain;
                        this.refrenshAtkAddition();
                        return [4 /*yield*/, this.Init(object)];
                    case 1:
                        _a.sent();
                        farLevel = 0;
                        allContent = gameEngine_1.default.getServices().localStorageSrv.getStorage(this.level_Save_Content);
                        if (allContent) {
                            object_1 = JSON.parse(allContent);
                            farLevel = object_1[this.m_mode].currLevel;
                        }
                        curPageIndex = Math.ceil(farLevel / 6);
                        this.pageNode.getComponent(cc.PageView).setCurrentPageIndex(curPageIndex - 1);
                        delete object[keyLength + 1];
                        return [2 /*return*/];
                }
            });
        });
    };
    LevelMeun.prototype.refrenshAtkAddition = function () {
        this.atkAdditionNode.active = this.m_mode == gameMode_json_1.GAME_MODE.NORMAL;
        this.lbAddition.string = "永久攻击：" + data_control_1.default.getNumberFormat(gameEngine_1.default.getManagers().peopleArcheryManager.getData().atkAddition);
        this.lbHpAddition.string = "永久回血：" + data_control_1.default.getNumberFormat(gameEngine_1.default.getManagers().peopleArcheryManager.getData().revitAlize);
        this.gouZiNode.active = this.m_mode == gameMode_json_1.GAME_MODE.LIANXIAN;
        this.lb_GouZi.string = data_control_1.default.getNumberFormat(gameEngine_1.default.getManagers().goldMinerManager.getData().hookLevel);
    };
    LevelMeun.prototype.Init = function (object) {
        return __awaiter(this, void 0, void 0, function () {
            var _this = this;
            return __generator(this, function (_a) {
                return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
                        var lastBtn, key, node, leftNum, btn;
                        return __generator(this, function (_a) {
                            lastBtn = null;
                            for (key in object) {
                                node = cc.instantiate(this.btnPrefab);
                                this.pages[this.curPageIndex].addChild(node);
                                leftNum = this.curPageIndex + 1;
                                this.pageTagNode.getComponent(cc.Label).string = leftNum + "/" + this.pages.length;
                                if (object[key]["hot"] == "hot") {
                                }
                                this.pageAddNum += 1;
                                if (this.pageAddNum >= 6) {
                                    this.curPageIndex += 1;
                                    this.pageAddNum = 0;
                                }
                                btn = node.getComponent(LevelBtn_1.default);
                                btn.Init(Number(key), this.m_mode, object[key]);
                                btn.lastBtn = lastBtn;
                                lastBtn = btn;
                            }
                            this.scheduleOnce(resolve, 0.1);
                            return [2 /*return*/];
                        });
                    }); })];
            });
        });
    };
    LevelMeun.prototype.pageEvents = function () {
    };
    LevelMeun.prototype.update = function (dt) {
        var ccPage = this.pageNode.getComponent(cc.PageView);
        var leftNum = ccPage.getCurrentPageIndex() + 1;
        this.pageTagNode.getComponent(cc.Label).string = leftNum + "/" + ccPage.getPages().length;
        this.btn_unlockAll.active = !gameEngine_1.default.getServices().userSrv.getLevelAllUnlockFlag();
    };
    // private readonly
    LevelMeun.prototype.onUnLockAllLevel = function (e, custom) {
        var _this = this;
        if (!MainRoot_1.default.LevelSystem.getIsUnLockAll()) {
            MainRoot_1.default.UIModel.showMessageBox("\u6240\u6709\u5173\u5361\u5DF2\u89E3\u9501");
            return;
        }
        var prams = {
            mode: this.m_mode,
            unlockCall: function () { },
            isShowOne: false,
            allCall: function () {
                MainRoot_1.default.UIModel.showMessageBox("\u6240\u6709\u5173\u5361\u5DF2\u89E3\u9501");
                MainRoot_1.default.LevelSystem.unAllLock(_this.m_mode);
                gameEngine_1.default.emit('refrashAll');
            },
            cancel: null
        };
        if (custom) {
            MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.UNLOCKALLPAGE, prams);
        }
        else {
            MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.UNLOCKPAGE, prams);
        }
    };
    __decorate([
        property({ type: cc.Prefab, displayName: "选关页面预制体" })
    ], LevelMeun.prototype, "pagePrefab", void 0);
    __decorate([
        property({ type: cc.Prefab, displayName: "选关按钮预制体" })
    ], LevelMeun.prototype, "btnPrefab", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "翻页插件" })
    ], LevelMeun.prototype, "pageNode", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "页面标签" })
    ], LevelMeun.prototype, "pageTagNode", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "模式文本" })
    ], LevelMeun.prototype, "lbMode", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "永久攻击加成文本" })
    ], LevelMeun.prototype, "lbAddition", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "永久回血加成文本" })
    ], LevelMeun.prototype, "lbHpAddition", void 0);
    __decorate([
        property({ type: cc.Node, displayName: "永久攻击加成节点" })
    ], LevelMeun.prototype, "atkAdditionNode", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "全部解锁按钮" })
    ], LevelMeun.prototype, "btn_unlockAll", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "钩子强化等级节点" })
    ], LevelMeun.prototype, "gouZiNode", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "钩子文本" })
    ], LevelMeun.prototype, "lb_GouZi", void 0);
    LevelMeun = __decorate([
        ccclass,
        disallowMultiple,
        menu('游戏页面/选关页')
    ], LevelMeun);
    return LevelMeun;
}(PageBase_1.default));
exports.default = LevelMeun;

cc._RF.pop();